package com.my.test.java.two.moredata.datas.share;

import com.my.test.java.two.moredata.datas.AbsResultSet;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by Administrator on 2016-11-25.
 */
public class ResultSetWrapper extends AbsResultSet {

    private boolean isEmpty = false;
    
    private boolean flag;
    
    private boolean isGoFirst = false;

    public ResultSetWrapper(){}

    public ResultSetWrapper(ResultSet rs) throws SQLException {
        if (isEmpty = !rs.next()) {
        	rs.previous();
        	isEmpty = false;
            return;
        }
        isEmpty = true;
        flag = true;
//        rs.first();
        setIndexResultSet(rs);
    }
    @Override
    public boolean next() throws SQLException {
    	if(flag){
    		flag = false;
    		isGoFirst = true;
    		return getIndexResultSet().first();
    	}else{
    		flag = false;
    		isGoFirst = false;
    		return getIndexResultSet().next();
    	}
//    	 boolean ff = flag?getIndexResultSet().first():getIndexResultSet().next();
//    	 flag = false;
//    	 return ff;
    }

    public boolean isEmpty() {
        return isEmpty;
    }

    public void setEmpty(boolean empty) {
        isEmpty = empty;
    }

	public boolean isFlag() {
		return flag;
	}

	public void setFlag(boolean flag) {
		this.flag = flag;
	}

	public boolean isGoFirst() {
		return isGoFirst;
	}

	public void setGoFirst(boolean isGoFirst) {
		this.isGoFirst = isGoFirst;
	}

}
